<!-- 详情 -->
<template>
	<div>
		<el-form :model="editForm" ref="editForm" :rules="rules" >
			<el-row>
				<el-col :span="12">
					<el-form-item label="测试名称" prop="testing_name">
						<el-input v-model="editForm.testing_name" readonly placeholder="请输入策略名称" size="large"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="状态" prop="state">
						<el-input v-if="editForm.state == 1" placeholder="请输入手机号" size="large" value='训练中' readonly></el-input>
						<el-input v-if="editForm.state == 2" placeholder="请输入手机号" size="large" value='已完成' readonly></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="交易笔数" prop="total_trades">
						<el-input v-model="editForm.test_result.total_trades" readonly placeholder="交易笔数" size="large"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="总收益" prop="total_pl">
						<el-input v-model="editForm.test_result.total_pl" readonly placeholder="总收益" size="large"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="手续费" prop="total_commission">
						<el-input v-model="editForm.test_result.total_commission" readonly placeholder="手续费" size="large"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="平均盈利" prop="avg_winning_trade">
						<el-input v-model="editForm.test_result.avg_winning_trade" readonly placeholder="平均盈利" size="large"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="平均盈利时间" prop="avg_win_duration">
						<el-input v-model="editForm.test_result.avg_win_duration" readonly placeholder="平均盈利时间" size="large"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="平均亏损" prop="avg_losing_trade">
						<el-input v-model="editForm.test_result.avg_losing_trade" readonly placeholder="平均亏损" size="large"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="平均亏损时间" prop="avg_loss_duration">
						<el-input v-model="editForm.test_result.avg_loss_duration" readonly placeholder="平均亏损时间" size="large"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="胜率" prop="winning_percent">
						<el-input v-model="editForm.test_result.winning_percent" readonly placeholder="胜率" size="large"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="最大连续盈利" prop="max_consec_win_trade">
						<el-input v-model="editForm.test_result.max_consec_win_trade" readonly placeholder="最大连续盈利" size="large"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="最大连续亏损" prop="max_consec_loss_trade">
						<el-input v-model="editForm.test_result.max_consec_loss_trade" readonly placeholder="最大连续亏损" size="large"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="最大回撤" prop="max_drawdown">
						<el-input v-model="editForm.test_result.max_drawdown" readonly placeholder="最大回撤" size="large"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="夏普比率" prop="sharpe_ratio">
						<el-input v-model="editForm.test_result.sharpe_ratio" readonly placeholder="夏普比率" size="large"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-for="(item,index) in editForm.images" :key="index">
					<el-form-item :label="item.name">
						<el-image style="width: 100%;" :src="item.url" :preview-src-list="[item.url]"> </el-image>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
	</div>
</template>

<script>
import {addStrategyAPI,editStrategyAPI,} from '@/api/index';

export default {
	name: 'editModel',
	props: {
		Infoitem: Object
	},
	data() {
	    return {
			title:'',
			editForm:{},
			rules: {
				strategy_name: [{ required: true, message: '请输入策略名称', trigger: 'blur' }]
			},
	    };
	},
	mounted() {
		console.log(this.Infoitem)
		this.editForm = this.Infoitem
	},
	methods:{
		saveEdit(){
			var that = this
			that.$refs.editForm.validate(valid => {
			    if (valid) {
					if(that.editForm.model_id){
						editStrategyAPI(that.editForm).then(res => {
							if(res.status == 200){
								that.$message.success(`修改成功`);
								that.closedialog();
							}else{
								that.$message.error(res.msg);
							}
						});
					}else{
						addStrategyAPI(that.editForm).then(res => {
							if(res.status == 200){
								that.$message.success(`添加成功`);
								that.closedialog();
							}else{
								that.$message.error(res.msg);
							}
						});
					}
			    } else {
			        console.log('error submit!!');
			        return false;
			    }
			});
		},
		closedialog() {
			this.$emit('closeDialog', false);
		}
	}
};
</script>

<style scoped>
.dialog-footer {
	width: 100%;
	text-align: right;
}
/deep/.el-col-12{
	padding: 0 15px;
}
</style>
